package com.Lixiaoqian.Gulangyu.ar_m.ui

import android.app.Activity
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Bundle
import com.Lixiaoqian.Gulangyu.R
import com.Lixiaoqian.Gulangyu.utils.Constant
import com.Lixiaoqian.Gulangyu.utils.PermissionsChecker
import com.Lixiaoqian.Gulangyu.utils.ToastUtils
import com.wikitude.architect.ArchitectJavaScriptInterfaceListener
import com.wikitude.architect.ArchitectStartupConfiguration
import com.wikitude.architect.ArchitectView
import com.wikitude.common.camera.CameraSettings
import org.json.JSONObject

class ARCamActivity : AbstractCamActivity(), ArchitectJavaScriptInterfaceListener {
    override fun onJSONObjectReceived(p0: JSONObject?) {//js回调处理

    }

    override fun getUrlListener(): ArchitectJavaScriptInterfaceListener {
        return this
    }

    override fun getArWidget(): ArchitectView {
        return findViewById(R.id.wd_architeView)
    }

    override fun getArFeatures(): Int {
        return ArchitectStartupConfiguration.Features.Geo
    }

    override fun getArLicenseKey(): String {
        return Constant.WIKITUDE_KEY
    }

    override fun getArCameraPosi(): CameraSettings.CameraPosition {
        return CameraSettings.CameraPosition.DEFAULT
    }


    override fun getWorldUrl(): String {
       return ""
    }

    companion object {
        fun startActivity(fromActivity: Activity) {
            fromActivity.startActivity(Intent(fromActivity, ARCamActivity::class.java))
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_arcam)
        PermissionsChecker.checkAndOpenPermiss(this,Constant.PERMISS_CAMERA)
        initAR()
    }

    override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults)
        for (i in permissions.indices){
            if(grantResults[i]==PackageManager.PERMISSION_DENIED){
                ToastUtils.showShort("${permissions[i]}权限被拒绝")
            }
        }
    }
}
